﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static HB.HttpServer.HttpServer;

namespace HB.HttpServer.Model
{
    internal class Router
    {
        Dictionary<string, Method> dic;
        public void Add(string url, Method data)
        {
            if (dic == null) { dic = new Dictionary<string, Method>(); }
            if (dic.ContainsKey(url))
            {
                throw new Exception("已存在相同路由信息");
            }
            dic.Add(url, data);
        }
        public Method Get_MenberInfo(string url)
        {
            if (dic == null) { return null; }
            if (dic.ContainsKey(url)) { return dic[url]; } else { return null; }

        }
        public string[] GetSupportURL(string key = null)
        {
            if (key == null)
            {
                return dic.Keys?.ToArray() ?? new string[0];
            }
            else
            {
                return dic.Keys?.Where(zz => zz.Contains(key)).ToArray() ?? new string[0];
            }

        }

    }
}
